<?php
namespace App\Master\Framework\View;
use  \Illuminate\Http\Request;

class AdminData {
    public static function orderBy($default = '')
    {
        $sorts = Request::capture()->input ('prop');
        $orders = Request::capture()->input ('orderBy', 'desc');
        $orders = $orders == 'asc' ? 'asc' :'desc';

        $order = [];
        if(!($sorts) || $sorts == 'null' ||  $sorts == 'undefined')
        {
            if($default = explode(',', $default))
            {
                if(isset($default[1]) && $default[0] && $default[1]) {
                    $order[] = ['sort'=>$default[0], 'orderBy'=>$default[1]];
                }
            }
        }else{
            $sorts = explode(',',$sorts);
            foreach ($sorts as $sort){
                $order[] = [
                    'sort' => $sort,
                    'orderBy' => $orders
                ];
            }
        }
        return $order;
    }

    public static function limit()
    {
        $pages = Request::capture()->input ('page', 1);
        $sizes = Request::capture()->input ('size', 15);
        if($pages === 1){
            $pages = 0;
        } else {
            $pages = (($pages - 1) * $sizes);
        }
        return [intval($pages), intval($sizes)];
    }

    public static function dateBetween($date)
    {
        if(!$date){
            return [strtotime(date('Y-m-d 00:00:00')), strtotime(date('Y-m-d 23:59:59'))];
        }
        return [strtotime($date.' 00:00:00'), strtotime($date.' 23:59:59')];
    }
}
